<?php
class LocationsController extends LiladsAppController {
    var $name = 'Locations';
    //var $uses = array('Lilads.Locations', 'Lilads.Banner');
	
	function show($location_id=null) {
		$this->layout = false;
    	if (!is_numeric($location_id)) {
    		$this->cakeError('error404');
		}
		
		App::import('model', 'Lilads.Banner'); $banner = new Banner();
    	if (Configure::read('Lilads.active')!==false) $this->set('banner', $banner->findForLocation($location_id));
    }
    
    function admin_index() {
    	$this->set('locations', $this->paginate());
    }
    
    function admin_add() {
    	$this->setAction('admin_edit');
    }
    
   	function admin_edit($id = null) {
		if (!empty($this->data)) {
			if ($this->Location->save($this->data)) {
				$this->Session->setFlash(__('Location has been saved.', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('Please verify that the information is correct.', true), null, null, 'error');
			}
		}
		if (is_numeric($id)) {
			$this->data = $this->Location->read(null, $id);
		}
	}

	function admin_delete($id = null) {
		if (is_numeric($id) && $this->Location->del($id)) {
			$this->Session->setFlash(__('Location has been deleted.', true));
			$this->redirect(array('action'=>'index'));
		} else {
			$this->cakeError('error404');
		}
	}
}
?>